package com.LeeCode;
/**
 * 乘最多水的容器
 * **/

public class Code011 {
    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        int res = new Code011().maxArea(height);
        System.out.println(res);
    }
    // 贪心算法， 每次去寻找有可能的最大值
    public int maxArea(int[] height) {
        int left = 0, right = height.length - 1;
        int res = 0;

        while (left < right) {
            int area = Math.min(height[left], height[right]) * (right - left);
            res = res < area ? area : res;
            if (height[left] < height[right])
                left++;
            else
                right--;
        }
        return res;
    }
}
